package com.xmuexp109.exp5.Controller;

import ch.qos.logback.classic.Logger;
import com.xmuexp109.exp5.model.ordersVo;
import io.swagger.annotations.Api;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



import javax.annotation.Resource;



@Service
@Api(value = "订单API", tags = "订单API")
@RestController
@RequestMapping(value = "/neworders", produces = "application/json;charset=UTF-8")
public class RocketController {
    @Resource
    private RocketMQTemplate rocketMQTemplate;

    @PostMapping("")
    public void sendmessage(@RequestBody ordersVo vo) {
        rocketMQTemplate.asyncSend("order-pay-topic", MessageBuilder.withPayload(vo).build(), new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {

             //System.out("success");
            }

            @Override
            public void onException(Throwable throwable) {
                //System.out("Exception");

            }
        });

    }
}
